<?php
/**
 * 文件表模型
 * 
 */
class fileModel extends model 
{
	public function __construct(){
		parent::__construct('beauty_file','file_id');
	}
	public function getFileInDir($dir_id,$user_id) {
		$cond = array('dir_id' =>$dir_id);
		$field = array('file_id','file_name','file_size','file_type','file_modify_time','dir_id');
		return $result = $this->findAll($cond,$field);
		
		//print_r($result);
	}
	public function getDirTree($user_id,$parnet_dir_id){
		if($parnet_dir_id == '0') {
			$cond = array('parent_dir_id'=>$parnet_dir_id,'user_id = 0 OR user_id'=>$user_id);
		} else {
			$cond = array('parent_dir_id'=>$parnet_dir_id,'user_id'=>$user_id);
		} 
		
		$field = array('dir_id','parent_dir_id','dir_name');
		$result = $this->findAll($cond,$field);
		echo $this->turnToJsonData($result);
	}
	private function turnToJsonData($data) {
		if(!empty($data)) {
			foreach($data as $row) {
				$tmp[] = array('text'=>$row->dir_name,'id'=>$row->dir_id,'cls'=>'folder','draggable'=>true);
			}
		}
		return json_encode($tmp);
	}

	public function getUserImages($user_id) {
		$query = "SELECT * FROM $this->table WHERE user_id = '$user_id' AND file_type IN ('image/gif','image/jpg','image/jpeg','image/png','image/bmp') ";
		return $this->execute($query);
	}
	
}
?>
